package com.zjxf.controller;

import com.zjxf.base.bean.vo.VoUmsUser;
import com.zjxf.base.common.JSONResponse;
import com.zjxf.base.common.OperationException;
import com.zjxf.base.common.SysConst;
import com.zjxf.controller.common.BaseController;
import com.zjxf.service.UmsUserService;
import com.zjxf.utils.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 用户管理
 *
 * @author ZhangWei
 * @date 2021/3/16/016 17:04
 */
@Api(tags = "用户接口")
@AllArgsConstructor
@RestController
@Validated
@RequestMapping(value = "app/user/")
public class UserController extends BaseController {
    private final UmsUserService umsUserService;

    /**
     * 用户注册或修改
     *
     * @param voUser 账号密码封装
     * @return
     * @throws OperationException 用户名已存在
     */
    @ApiOperation(value = "用户注册或修改")
    @PostMapping(value = "addOrUpdate")
    public JSONResponse addOrUpdate(@Valid @RequestBody VoUmsUser.addOrUpdate voUser) throws OperationException {
        umsUserService.addOrUpdate(voUser);
        return success(SysConst.SUCCESS);
    }

    /**
     * 用户登录
     * @param voUser 账号密码封装
     * @return
     */
    @ApiOperation(value = "用户登录")
    @PostMapping(value = "login")
    public JSONResponse login(@Valid @RequestBody VoUmsUser.login voUser) {
        LoginUtil.login(voUser.getUsername(), voUser.getPassword(), voUser.getRemeberMe(), voUser.getType());
        return success(SysConst.LOGIN_SUCCESS);
    }

    @ApiOperation(value = "查看本用户信息")
    @PostMapping(value = "findUserInfo")
    public JSONResponse findUserInfo() {
        return null;
    }

    @ApiOperation(value = "用户填加收获地址")
    @PostMapping(value = "addAddress")
    public JSONResponse addAddress() {
        return null;
    }

    @ApiOperation(value = "查看订单")
    @PostMapping(value = "findOrders")
    public JSONResponse findOrders() {
        return null;
    }

}
